package com.blockmeta.bbs.immodule.activity;

import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.view.View;

import com.blockmeta.bbs.baselibrary.base.adapter.FragmentVPAdapter;
import com.blockmeta.bbs.baselibrary.widget.tab.SlidingTabLayout;
import com.blockmeta.bbs.businesslibrary.base.BaseActivity;
import com.blockmeta.bbs.businesslibrary.launch.IMConfigYMAL;
import com.blockmeta.bbs.businesslibrary.pojo.IMConfigPOJO;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.R2;
import com.blockmeta.bbs.immodule.bean.Params;
import com.blockmeta.bbs.immodule.fragment.CirclesForJoinFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author airthor
 * @date 2019/2/18
 * 加入圈子
 */
public class JoinCircleActivity extends BaseActivity {
    @BindView(R2.id.circle_tab)
    SlidingTabLayout mCircleTab;
    @BindView(R2.id.view_pager)
    ViewPager mViewPager;
    protected static IMConfigPOJO imConfigPOJO = IMConfigYMAL.getIMConfig();

    @Override
    protected boolean showTitle() {
        return true;
    }

    @Override
    public View setView() {
        return getLayoutInflater().inflate(R.layout.activity_join_circle, null);
    }

    @Override
    protected void initialize() {
        super.initialize();
        setTitleText("加入圈子");
        List<Fragment> fragments = new ArrayList<>(8);
        List<IMConfigPOJO.CircleType> circleTypes = imConfigPOJO.getCircleType();
        int size = circleTypes.size();
        List<String> tabsList = new ArrayList<>();

        Bundle bundle = new Bundle();
        bundle.putInt(Params.CIRCLE_TYPE, 0);
        CirclesForJoinFragment fragment = CirclesForJoinFragment.getFragmentInstance(bundle);
        fragments.add(fragment);
        tabsList.add("热门");
        for (int i = 0; i < size; i++) {
            IMConfigPOJO.CircleType type = circleTypes.get(i);
            bundle = new Bundle();
            bundle.putInt(Params.CIRCLE_TYPE,type.getId());
            fragment = CirclesForJoinFragment.getFragmentInstance(bundle);
            fragments.add(fragment);
            tabsList.add(type.getName());
        }
        mViewPager.setAdapter(new FragmentVPAdapter(getSupportFragmentManager(),fragments));
        mViewPager.setOffscreenPageLimit(circleTypes.size());
        String[] tabs = tabsList.toArray(new String[tabsList.size()]);
        mCircleTab.setViewPager(mViewPager,tabs);
    }

    @Override
    public boolean showRight() {
        return true;
    }

    @Override
    public int showRightImg() {
        return R.drawable.title_bar_search;
    }

    @Override
    public void toDoRightSomething() {
        Intent intent = new Intent(mContext,SearchCircleActivity.class);
        startActivity(intent);
        finish();
    }
}
